import { loginApi } from '@/api/user'
import router from '@/router'
const state = {
  token: null
}
const mutations = {
  setToken (state, token) {
    state.token = token
  },
  removeToken (state) {
    state.token = null
  }
}
const actions = {
  async loginAction ({ commit }, data) {
    const res = await loginApi(data)
    // console.log(res)
    commit('setToken', res)
  },
  logout ({ commit }) {
    commit('removeToken')
    router.push('/login')
  }
  /* async imgApi ({ commit }, data) {
    const res = await imgApi(data)
    // console.log(window.URL.createObjectURL(res.data))
    const src = window.URL.createObjectURL(res)
    return src

  //   // console.log(res)
  } */
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
